<script type="text/javascript">
$(document).ready(function()
{
	$('#sortable_questions_<?php echo $currentquestion['Questiongroup']['id']?>').sortable({

	   stop: function(event, ui) {		   	
			var question_order_array = $( "#sortable_questions_<?php echo $currentquestion['Questiongroup']['id'] ?>" ).sortable("toArray");
			$.post("/questions/reorder/", { 'data[questions]': [question_order_array] });
	   }
	});
});

</script>
<?php
	$assessment_breadcrum = $ajax->link(
		'Assessment',
		array( 'controller' => 'questiongroups', 'action' => 'ajax_get', $assessment['Assessment']['id'] ),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading')
	);
	$questiongroup_breadcrum = $ajax->link(
		'Question Group',
		array( 'controller' => 'questiongroups', 'action' => 'ajax_edit', $currentquestion['Questiongroup']['id'] ),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading')
	);
	
	$question_breadcrum = $ajax->link(
		'Questions',
		array( 'controller' => 'questions', 'action' => 'ajax_get', $currentquestion['Questiongroup']['id'] ),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading')
	);

?>
<div id="whiteBG">
<div id="crumb"><ul>
	<li class="crumbMiddle" id="crumb01"><?php echo $assessment_breadcrum;?></li>
	<li class="crumbMiddle" id="crumb02mid"><?php echo $questiongroup_breadcrum;?></li>
	<li class="crumbMiddle" id="crumb03on"><?php echo $question_breadcrum;?></li>
	<li class="crumbMiddle" id="crumb04">Question</li>
	<li class="crumbMiddle" id="crumb05">Answers</li>
	<li class="crumbMiddle" id="crumb06">Answer</li>
</ul></div> 
<div class="assessment">
	<div class="eTitle">
		<h2><?php echo $currentquestion['Questiongroup']['name'];?></h2>
	</div>
<div class="aTable">
	<div class="aTableHeader">
		<span class="aTableDelete">Delete</span>
		<span class="aTableDuplicate">Duplicate</span>
		<span class="aTableEdit">Edit</span>
		<span class="aTableTitle">Question Title</span>
		<span class="aTableQuestion">Answers</span>
	</div>
<?php 
	$questions = '';
	$i = 0;//switch between 1 and 0 to toggle between the two list classes
	foreach ($data['Question'] as $question)
	{
		$question_delete_ajax = $ajax->link(
			'[x]',
			array( 'controller' => 'questions', 'action' => 'ajax_delete', $question['id'] ),
			array( 'update' => 'edit_div_'.$data['Questiongroup']['assessment_id'], 'confirm' => 'Are you sure?', 'indicator' => 'loading')
		);

		$question_delete_ajax_img = str_replace('[x]','<span class="iconDelete"></span>',  $question_delete_ajax);

		$question_duplicate_ajax = $ajax->link(
			'[x]',
			array( 'controller' => 'questions', 'action' => 'ajax_duplicate', $question['id'].'/'.$data['Questiongroup']['id'] ),
			array( 'update' => 'edit_div_'.$data['Questiongroup']['assessment_id'], 'indicator' => 'loading')
		);

		$question_duplicate_ajax_img = str_replace('[x]','<span class="iconDuplicate"></span>',  $question_duplicate_ajax);

		$question_edit_ajax = $ajax->link(
			'[x]',
			array( 'controller' => 'questions', 'action' => 'ajax_edit', $question['id'] ),
			array( 'update' => 'edit_div_'.$data['Questiongroup']['assessment_id'], 'indicator' => 'loading')
		);

		$question_edit_ajax_img = str_replace('[x]','<span class="iconEdit"></span>',  $question_edit_ajax);
		
		$question_answers = $ajax->link(
				'[x]',
				array( 'controller' => 'answers', 'action' => 'ajax_get', $question['id'] ),
				array( 'update' => 'edit_div_'.$data['Questiongroup']['assessment_id'], 'indicator' => 'loading_edit')
			);

			$question_answers_img = str_replace('[x]','<span class="iconAnswer"></span>',  $question_answers);

		if (strlen($question['name']) > 40){
			$question['name'] = substr($question['name'],0,40);
			$question['name'] .= '..';
		}
		if($i == 0)
		{
			$questions .=  '<div class="aTableRowA" id="'.$question['id'].'">';
			$i = 1;
		}
		else
		{
			$questions .=  '<div class="aTableRowB" id="'.$question['id'].'">';
			$i = 0;
		}
		$questions .=  
		'
			<li id="'.$question['id'].'">
				<span class="aTableDelete">'.$question_delete_ajax_img.'</span>
				<span class="aTableDuplicate">'.$question_duplicate_ajax_img.'</span>
				<span class="aTableEdit">'.$question_edit_ajax_img.'</span>
				<span class="aTableTitle">'.$question['name'].'</span>
				<span class="aTableQuestion">'.$question_answers_img.'</span>
			</li>
			</div>
		';
	}
	
	echo '<ul id="sortable_questions_'.$currentquestion['Questiongroup']['id'].'">
			'.$questions.'
		  </ul>';
		  
  $question_add_ajax = $ajax->link(
		'[x]',
		array( 'controller' => 'questions', 'action' => 'ajax_add', $data['Questiongroup']['id'] ),
		array( 'update' => 'edit_div_'.$data['Questiongroup']['assessment_id'], 'indicator' => 'loading_question')
	);
	$question_add_ajax_img = str_replace('[x]','<span class="iconNew"></span><p>Add Question</p>',  $question_add_ajax);
	
	echo "<div class='aTableRowC'" . $question_add_ajax_img . "</div>" // . " Add Question";

?>
</div>